// FrogFileListDialog.cpp : Implementation of CFrogFileListDialog

#include "stdafx.h"
#include "FrogFileListDialog.h"
#include "FrogMessageBox.h"

// CFrogFileListDialog
CFrogFileListDialog::CFrogFileListDialog(HICON hIcon):
CFrogBaseDialog(hIcon),
m_FileList(L"FileList.txt"),
m_IncludeSubfolders(false),
m_Indent(false),
m_OutputFileType(0),
m_Html(false)
{
}

LRESULT CFrogFileListDialog::OnInitDialog(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
{
	CFrogBaseDialog::OnInitDialog(uMsg, wParam, lParam, bHandled);
	DoDataExchange(FALSE);

	CEdit editFileList;
	editFileList.Attach(GetDlgItem(IDC_EDIT_FILE_LIST));
	editFileList.SetSel(0, editFileList.GetWindowTextLength() - 4);
	editFileList.SetFocus();

	::EnableWindow(GetDlgItem(IDC_CHECK_INDENT), FALSE);

	return 0;
}

LRESULT CFrogFileListDialog::OnClickedOK(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled)
{
	bHandled = TRUE;
	// TODO: Add your control notification handler code here
	DoDataExchange(TRUE);

	if (m_FileList == L"")
	{
		FrogMessageBox(m_hWnd, L"Cannot Enter Empty FileName", L"FileName Validation", 0);
		return TRUE;
	}

	if (!FilerFrogUtils::IsFileNameValid(wstring(m_FileList)))
	{
		FrogMessageBox(m_hWnd, L"A file name cannot contain any of the following characters:\n\\ / : * ? \" < > |", L"File Name Validation", 0);
		return TRUE;
	}

	m_Html = m_OutputFileType != 0;

	if (!m_IncludeSubfolders)
	{
		m_Indent = false;
	}

	EndDialog(wID);
	return 0;
}

LRESULT CFrogFileListDialog::OnRadioTextBnClicked(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled)
{
	DoDataExchange(TRUE);

	wstring ext = FilerFrogUtils::GetFileNameExtension(wstring(m_FileList));
	wstring name = FilerFrogUtils::GetFileNameWithoutExtension(wstring(m_FileList));

	if (ext != L"")
	{
		if (m_OutputFileType == 0) // Text
		{		
			name = name + L".txt";	
		}
		else
		{
			name = name + L".html";	
		}

		m_FileList = name.c_str();

		DoDataExchange(FALSE);
	}

	return 0;
}

LRESULT CFrogFileListDialog::OnCheckSubfoldersBnClicked(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled)
{
	DoDataExchange(TRUE);

	if (m_IncludeSubfolders)
	{
		::EnableWindow(GetDlgItem(IDC_CHECK_INDENT), TRUE);
	}
	else
	{
		::EnableWindow(GetDlgItem(IDC_CHECK_INDENT), FALSE);
	}

	return 0;
}